package Logic.LogicUnitTest;

import static org.junit.Assert.assertEquals;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import org.junit.Test;

import com.joestelmach.natty.Parser;

import Logic.DSQueryFactory;
import Logic.DSTaskFactory;
import Object.DSException;
import Object.DSQuery;
import Task.DSTask;
//@author A0105536L
/****************************************************************************
 * Class DSTaskFactoryTest. This class is to test DSTaskFactory
 * 
 */
public class DSTaskFactoryTest {
	DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy",Locale.ENGLISH); 
	Parser nattyParser = new Parser();
	
	@Test
	public void test_Tags() throws ParseException, DSException {
		DSTaskFactory tf = new DSTaskFactory();
		DSTask task = new DSTask();
		task.addTag("tag1");
		task.addTag("tag2");
		task.addTag("test");
		// To test tag.
		assertEquals(task.getTaskTags(),tf.createNewTask("test tag tag1 tag2 test").getTaskTags()); 
	}
	@Test
	public void test_Keywords() throws ParseException, DSException {
		DSTaskFactory tf = new DSTaskFactory();
		DSTask t = new DSTask();
		t.setTaskName("keyword test");
	
		// To test keyword
		assertEquals(t.getTaskName(),tf.createNewTask("keyword test").getTaskName()); 
	}
	
	@Test
	public void test_endDate() throws ParseException, DSException {
		DSTaskFactory tf = new DSTaskFactory();
		DSTask t = new DSTask();
		
		t.setTaskEndDate(nattyParser.parse("mar 3").get(0).getDates().get(0));
		// To test after an end date
		assertEquals(t.getTaskEndDate().toString(),tf.createNewTask(" by 3 mar").getTaskEndDate().toString());
	}
	
	
	@Test
	public void test_Multiple() throws ParseException, DSException {
		DSTaskFactory tf = new DSTaskFactory();
		DSTask test = new DSTask();
		DSTask t = new DSTask();
		t.addTag("2103");
		t.addTag("tut");
		t.setTaskName("meeting");
		t.setTaskEndDate(nattyParser.parse("mar 3").get(0).getDates().get(0));
		
		test = tf.createNewTask("meeting by mar 3 tag 2103 tut");
		// Multiple criteria for adding.
		// to test end date
		assertEquals(t.getTaskEndDate().toString(),test.getTaskEndDate().toString());

		// to test tags
		assertEquals(t.getTaskTags(),test.getTaskTags());
		// to test keywords     Noted: there is "after" in keyword also, to test whether it is correct or not
		assertEquals(t.getTaskName(),test.getTaskName());
		
	}

}
